package com.book.controller;

import com.book.dto.ApplyPage;
import com.book.entity.Apply;
import com.book.service.ApplyService;
import com.book.utils.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
/**
 * @author yicheng
 */
@RestController
@RequestMapping("/apply")
public class ApplyController {
    @Autowired
    private ApplyService applyService;

    /**
     * 获取某个帖子的所有一级评论
     */
    @GetMapping("/getFirst")
    public ResponseResult getFirst(int postId,int currentPage,int pageSize){
        return applyService.getFirst(postId,currentPage,pageSize);
    }

    /**
     * 获取某个帖子的所有二级评论
     */
    @GetMapping("/getSecond")
    public ResponseResult getSecond(int postId, int parentApply){
        return applyService.getSecond(postId, parentApply);
    }

    @PostMapping("/addApply")
    public ResponseResult addApply(@RequestBody Apply apply){
        return applyService.addApply(apply);
    }

    /**
     * 获取自己的所有主动回复，按条件查找一级或二级
     */
    @PostMapping("/getSelfApply")
    public ResponseResult getSelfApply(@RequestBody ApplyPage applyPage){
        return applyService.getSelfApply(applyPage);
    }

    @GetMapping("/deleteMyApply")
    public ResponseResult deleteMyApply(@RequestParam int id){
        return applyService.deleteMyApply(id);
    }

    /**
     * 获取自己的所有被回复，按条件查找一级或二级
     */
    @PostMapping("/getApplyMe")
    public ResponseResult getApplyMe(@RequestBody ApplyPage applyPage){
        return applyService.getApplyMe(applyPage);
    }


    /**
     * 管理员查询所有的回复
     */
    @PostMapping("/getApplies")
    public ResponseResult getApplies(@RequestBody ApplyPage applyPage){
        return applyService.getApplies(applyPage);
    }

    /**
     * 管理员删除不正常的回复
     * @return id 回复的id
     */
    @GetMapping("/deleteApply")
    public ResponseResult deleteApply(@RequestParam int id){
        return applyService.deleteApply(id);
    }
}
